<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace Think\Template\TagLib;
use Think\Template\TagLib;
/**
 * Html标签库驱动
 */
class Upload extends TagLib{
    // 标签定义
    protected $tags   =  array(
        // 标签定义： attr 属性列表 close 是否闭合（0 或者1 默认1） alias 标签别名 level 嵌套层次
        'image'    => array('attr'=>'id,name,style,width,height,type','close'=>1),
    );
    /**
     * editor标签解析 插入可视化编辑器
     * 格式： <html:editor id="editor" name="remark" type="FCKeditor" style="" >{$vo.remark}</html:editor>
     * @access public
     * @param array $tag 标签属性
     * @return string|void
     */
    public function _image($tag,$content) {
        return <<<EOF
<script language="JavaScript" src="__PUBLIC__/js/Home/uploadImg/swfupload.js"></script>
<script language="JavaScript" src="__PUBLIC__/js/Home/uploadImg/swfupload.queue.js"></script>
<script language="JavaScript" src="__PUBLIC__/js/Home/uploadImg/fileprogress.js"></script>
<script language="JavaScript" src="__PUBLIC__/js/Home/uploadImg/handlers.js"></script>

<script type="text/javascript">
    var swfu;
    var imgname = "图片名称";
    window.onload = function() {
        var settings = {
            flash_url : "__PUBLIC__/js/Home/uploadImg/swfupload.swf",
            upload_url: "{:U('/upload/image')}",
            post_params: {"limit" : "1"},
            file_size_limit : "100 MB",
            file_types : "*.jpg;*.jpeg;*.png;*.bmp",
            file_types_description :  "Web Image Files",
            file_upload_limit : 10,
            file_queue_limit : 0,
            custom_settings : {
                progressTarget : "fsUploadProgress",
                cancelButtonId : "btnCancel"
            },
            debug: false,
            // Button settings
            button_image_url: "__PUBLIC__/image/Home/uploadim1.jpg",
            button_width: "103",
            button_height: "39",
            button_placeholder_id: "spanButtonPlaceHolder",
            button_text: '',
            button_text_style: ".theFont { font-size: 16; }",
            button_text_left_padding: 0,
            button_text_top_padding: 0,
            file_queued_handler : fileQueued,
            file_queue_error_handler : fileQueueError,
            file_dialog_complete_handler : fileDialogComplete,
            upload_start_handler : uploadStart,
            upload_progress_handler : uploadProgress,
            upload_error_handler : uploadError,
            upload_success_handler : uploadSuccess,
            upload_complete_handler : uploadComplete,
            queue_complete_handler : queueComplete
        };
        swfu = new SWFUpload(settings);
    };

</script>
<div>
    <div class="form_pictext_btn">
        <span id="spanButtonPlaceHolder"></span>
        <input id="btnCancel" type="hidden" value="" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />
        <input type="hidden" id="uploadparam">
    </div>
    <ul  id="imageView"></ul>
</div>
<script>
    $(document).ready(function(){
        //var editValue =value;
        var editValue = "";
        //console.log(editValue);
        if(editValue) {
            //var editObject =  eval(editValue);
            var editImgHtml = "";
            editImgHtml+= "<li><img src='"+editValue+"'><a style='cursor:pointer' onclick='$(this).parent().remove()'>&nbsp;删除</a><input type='hidden' name='"+imgname+"[]' value='"+editValue+"'></li>";
            $("#imageView").html(editImgHtml);
            $("#uploadparam").val('1');
        }
    });
</script>
EOF;




    }

}